package main

import (
	"context"
	"fmt"

	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
)

func main() {
	config, _ := clientcmd.BuildConfigFromFlags("", "config")
	clientset, _ := kubernetes.NewForConfig(config)

	labelSelector := "k8s-app=kube-dns"

	pods, err := clientset.CoreV1().Pods("kube-system").List(context.TODO(), metav1.ListOptions{LabelSelector: labelSelector})
	if err != nil {
		panic(err)
	}

	for _, pod := range pods.Items {
		fmt.Printf("pod name: %s\n", pod.Name)
	}

	// for _, pod := range pods.Items {
	// 	fmt.Printf("pod name: %s podlabels:", pod.Name)
	// 	for key, value := range pod.Labels {
	// 		fmt.Printf("%s=%s ", key, value)
	// 	}
	// 	fmt.Println()
	// }

	// var runningPods []v1.Pod
	// for _, pod := range pods.Items {
	// 	if pod.Status.Phase == v1.PodRunning {
	// 		runningPods = append(runningPods, pod)
	// 	}
	// }

	// for _, pod := range runningPods {
	// 	fmt.Printf("pod name: %s,pod status: %s\n", pod.Name, pod.Status.Phase)
	// }

	// deployments, _ := clientset.AppsV1().Deployments("default").List(context.TODO(), metav1.ListOptions{})
	// for _, deployment := range deployments.Items {
	// 	fmt.Println(deployment.Name)
	// }

	// services, _ := clientset.CoreV1().Services("default").List(context.TODO(), metav1.ListOptions{})
	// for _, service := range services.Items {
	// 	fmt.Println(service.Name)
	// }

	// nodes, _ := clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
	// for _, node := range nodes.Items {
	// 	fmt.Println(node.Name)
	// }

}
